package com.jugheadzhou.auth.task;

import com.jugheadzhou.auth.mapper.UserTokenMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author jugheadzhou
 * @date 2021-11-28
 */
@Slf4j
@Component
public class AuthTask {

    @Resource
    private UserTokenMapper userTokenMapper;

    /**
     * 定时删除过期的登陆记录
     */
    @Scheduled(fixedRate = 1000 * 30)
    public void deleteExpiredJob() {
        if (log.isDebugEnabled()) {
            log.debug("开始删除过期的登陆记录");
        }
        Integer expiredCount = userTokenMapper.deleteExpired();
        if (log.isDebugEnabled()) {
            log.debug("删除过期的登陆记录数量：{}", expiredCount);
        }
    }

}
